package web.listner;


import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

public class MythreeListner  implements HttpSessionBindingListener {

    @Override
    public void valueBound(HttpSessionBindingEvent httpSessionBindingEvent) {
        ServletContext servletContext = httpSessionBindingEvent.getSession().getServletContext();
        int onLineNum = (int)servletContext.getAttribute("onLineNum");
        servletContext.setAttribute("onLineNum",onLineNum+1);
        System.out.println("当session去添加我们这一个类为属性，才会增加，在线访问人数"+(onLineNum+1));
    }

    @Override
    public void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent) {
        ServletContext servletContext = httpSessionBindingEvent.getSession().getServletContext();
        int onLineNum = (int)servletContext.getAttribute("onLineNum");
        servletContext.setAttribute("onLineNum",onLineNum-1);
        System.out.println("当session去添加我们这一个类为属性，才会增加，在线访问人数"+(onLineNum-1));
    }
}
